import { createRouter, createWebHistory } from 'vue-router';

import { constantRoutes as routes } from './routes';

export async function setupRouter(app) {
	app.use(router);
	// 创建路由守卫
	// 路由准备就绪后挂载APP实例
	await router.isReady();
}

export const router = createRouter({
	history: createWebHistory(),
	// routes: constantRoutes.concat(asyncRoutes),
	routes,
	scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 定义一个resetRouter 方法，在退出登录后或token过期后 需要重新登录时，调用即可
export function resetRouter() {
	const newRouter = createRouter();
	router.matcher = newRouter.matcher;
}
